#!/bin/python3
# -*- coding: utf-8 -*-

# flask调试
import os
os.environ['FLASK_DEBUG'] = '1'


from flask import Flask, url_for, request, render_template


app = Flask(__name__)

# 传入参数
@app.route('/hello/<username>')
def hello_world(username):
	return 'Hello {0} !'.format(username)

# 反解url	
@app.route('/')
def index():
	return 'Index page!\n {0}'.format(url_for('hello_world', username='tangwenjun'))
	

# 判断request请求方法
@app.route('/aaa', methods=['GET'])
def aaa():
	if request.method == 'GET':
		return "aaa with GET method!"
	else:
		return "aaa with {0} method".forma(request.method)
		

# 使用模版
@app.route('/ccc')
@app.route('/ccc/<name>')
def ccc(name=''):
	app.logger.info('Locals [{0}]'.format(locals()))
	# return render_template('ccc.html', name=name) 或者如下
	return render_template('ccc.html', ** locals())
	
	
if __name__ == '__main__':
	app.run()